#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi

#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc3_LIH_431G_tmom.info <<%EOF%
   cc3_LIH_431G_tmom
   -----------
   Molecule:         LiH 
   Theory Level:     CC3 / 4-31G
   Test Purpose:     Transition moment between the ground and an 
                     excited state; non-totally symmetric operator.
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc3_LIH_431G_tmom.mol <<%EOF%
BASIS
4-31G
blubber
blubber
    2    2  X  Y      1.00D-15
        3.0   1    1    1
Li    0.0000000000000000   0.000000000   1.30000000
        1.0   1    1    1
H     0.0000000000000000   0.000000000   0.00000000
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc3_LIH_431G_tmom.dal <<%EOF%
**DALTON
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
.DIPVEL
.ANGMOM
**WAVE FUNCTION
.CC
*SCF INPUT
.THRESH
 1.0D-12
.NODIIS
*CC INP
.NSIMLE
  1
.CC3
.RESTART
.PRINT
 2
.THRENR
1.0D-14
.THRLEQ
1.0D-14
.MXLRV
  1000
.MAX IT
  1000
*CCEXCI
.THREXC
 1.0D-13
.TOLSC
 1.0D-12
.NCCEXCI
 1 0 0 0
 0 0 0 0
*CCOPA
.OPERATOR
ZDIPLEN
**END OF DALTON
%EOF%
#######################################################################



#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL > cc3_LIH_431G_tmom.check
cat >>cc3_LIH_431G_tmom.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF, MP2 and CC3 energies:
CRIT1=`$GREP "Total SCF   energy: * -7\.5755889529" $log | wc -l`
CRIT2=`$GREP "Total MP2   energy: * -7\.5941367951" $log | wc -l`
CRIT3=`$GREP "Total CC3   energy: * -7\.6021077986" $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3` 
CTRL[1]=6
ERROR[1]="ENERGIES NOT CORRECT"


# CC3 transition moment :
CRIT1=`$GREP  " *\| *ZDIPLEN *\| *( |-|-0|0)\.48586718 *\| *( |-|-0|0)\.94072362 *\| *( |0)\.45706673 *\|" $log | wc -l`

TEST[2]=$CRIT1
CTRL[2]=1
ERROR[2]="CC3 TRANSITION MOMENT NOT CORRECT"

# CC3 excitation energies:
CRIT1=`$GREP  " *\| *\^1A1 *\| *1 *\| *( |0)\.1020058 *\| *2\.77572 *\| *22387\.69. *\| *91\.92 *\|" $log | wc -l`
TEST[3]=$CRIT1
CTRL[3]=1
ERROR[3]="CC3 EXCITATION ENERGIES NOT CORRECT"

PASSED=1
for i in 1 2 3
do 
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done 

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM 
  exit 1
fi

%EOF%
#######################################################################
